//
//  ViewController.m
//  WebView
//
//  Created by lanou on 16/5/16.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // UIWebView的使用
    // UIWebView就是加载在我们程序内部的一个网页，这个网页可以调整大小，可以让我们在不跳出应用程序的情况下打开一个网址
    /*
     1、如果需要打开某一个网页，需要用到
     2、某一个界面布局非常复杂
     3、某一个界面的布局需要经常变动
     */
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, 375, 667 - 20)];
    // [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];
    
    NSString *string = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://pianke.me/webview/539e50698ead0ef96e0000a3"]] encoding:NSUTF8StringEncoding];
    NSLog(@"%@",string);
//    [string stringByReplacingOccurrencesOfString:@"自由写作" withString:@"Cc"];
    
    string = [string stringByReplacingOccurrencesOfString:@"http://pkimg.image.alimmdn.com/upload/20140616/59ee7bed94056cc5465ba2bd7e42dd2d.png!288x" withString:@"http://pkicdn.image.alimmdn.com/timeline/tagimgs/450a81f59bca0bce987413093c9e1d65.jpg"];
    string = [NSString stringWithFormat:@"<head><style>img{width:50%%px !important;}</style></head>%@",string];
    
    NSRange range1 = [string rangeOfString:@"我这店全年24小时无休"];
    NSRange range2 = [string rangeOfString:@"无法超越！"];
    string = [string stringByReplacingCharactersInRange:NSMakeRange(range1.location, range2.location + range2.length - range1.location) withString:@""];
    [webView loadHTMLString:string baseURL:nil];
    [self.view addSubview:webView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end








